import Dialog from '../../../../dist/dialog/dialog';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    evaluation_show: false,
    timeList: [{
      id: 1,
      name: '付款时间'
    },{
      id: 2,
      name: '审核时间'
    },{
      id: 3,
      name: '接单时间'
    }],
    type: "individual",
    order_id: "",
    detailData: {},
    show_more: false,
    show_icon: false,
    imgPath: app.globalData.imgPath,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      type: options.type,
      order_id: options.order_id
    })
    this.getOrderDetail();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  // 我要评价
  btnEvaluation() {
    this.setData({
      evaluation_show: !this.data.evaluation_show
    })
  },
  getOrderDetail () {
    let url = this.data.type == "individual" ? "plugin.be-within-call.frontend.order.personal-need.detail" : "plugin.be-within-call.frontend.order.enterprise-need.detail"
    let baseUrl = app.getNetAddresss(url);
    app._postNetWork({
      url: baseUrl,
      data: {
        oid: this.data.order_id
      },
      success: ({data : { data,result,msg }}) => {
        if (result !== 1) {
          wx.showToast({
            title: msg,
          });
          return false;
        }
        this.setData({
          detailData: data
        })
        var query = wx.createSelectorQuery();
        query.select('.tec_text').boundingClientRect();
        query.exec( (res) => {
          //res就是 所有标签为v1的元素的信息 的数组
          //取高度
          if(res[0].height > 24) {
            this.setData({
              show_more: true,
              show_icon: true
            })
          }
        })
      }
    });
  },
  evenButtonModels(ev) {
    let citem = ev.currentTarget.dataset.citem;
     if(citem.value == 'pay') {
       wx.navigateTo({
         url: '/packageD/buy/orderPay/orderPay?order_id=' + this.data.order_id + '&status=2'
       });
     }else if(citem.value == 'cancel-pay' || citem.value == 'enterprise-cancel-pay') {
       let baseUrl = app.getNetAddresss(citem.api);
       app._postNetWork({
         url: baseUrl,
         data: { oid: this.data.order_id },
         success: ({data : { data,result,msg }}) => {
            if (result !== 1) {
              app.tips(msg)
              return false;
            }
            this.getOrderDetail();
         }
       });
     }else if(citem.value == 'receive') {
       Dialog.confirm({
         title: '提示',
         message: '是否确认完成',
       })
         .then(() => {
            let baseUrl = app.getNetAddresss(citem.api);
            app._postNetWork({
                url: baseUrl,
                data: { oid: this.data.order_id },
                success: ({data : { data,result,msg }}) => {
                    if (result !== 1) {
                      app.tips(msg)
                      return false;
                    }
                    this.getOrderDetail();
                }
            });
         })
         .catch(() => {
         });
     }else if(citem.value == 'publish') {
       this.setData({
         evaluation_show: true
       })
     }
  },
  btnShowMore(ev) {
    this.setData({
      show_more: ev.currentTarget.dataset.status
    })
  },
  commentEvent() {
    this.getOrderDetail();
  },
  gophone() {
    wx.makePhoneCall({
      phoneNumber: this.data.detailData.has_one_shifu.mobile
    });
  }
})